package com.lry;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.LongAdder;

public class Redis {
    private Map<String, LongAdder> map;
    private SegmentLock<String> segmentLock;

    public Redis(){
        map = new ConcurrentHashMap<>();
        segmentLock = new SegmentLock<>();
    }

    public void set(String key, Integer value){
        LongAdder longAdder = new LongAdder();
        longAdder.add(value);
        map.put(key,longAdder);
    }

    public Integer get(String key){
        LongAdder longAdder = map.get(key);
        if(longAdder==null){
            return null;
        }
        return longAdder.intValue();
    }


    public Integer incr(String key,Integer n){
        LongAdder longAdder = map.get(key);
        if(longAdder==null){
            return null;
        }
        longAdder.add(n);
        return longAdder.intValue();
    }
}
